/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package scrabble;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

/**
 *
 * @author KhoufiAsma
 */
public class ChoixEchange  {
        
    private  ButtonGroup gb= new ButtonGroup();
    private  JRadioButton r1 = new JRadioButton("Echanger une lettre avec le sachet"); 
    private  JRadioButton r2 = new JRadioButton("Echanger votre joker et une lettre du plateau");
    private  JRadioButton r3 = new JRadioButton("Echanger une lettre avec un joker du plateau");
    private JFrame fe=new JFrame();
   
    public int ch;
    JButton entree = new JButton("Entrez"); 
     JPanel fen;
         private Chevalet chev;
         private Plateau plat;
  
  
    private MonListenerEchange l= new MonListenerEchange();

  
    
    
 

  public ChoixEchange(Chevalet chev, Plateau plat) throws InterruptedException { 
      fe.setTitle("Quel échange voulez-vous effectuez?");
      this.chev=chev;
      this.plat=plat;

    fe.setBounds(600,300,400,150); 
    fe.setLayout(new GridLayout(4,1)); 
    r1.setBounds(20, 25, 88, 23);  
    r2.setBounds(20, 55, 108, 23);
    r1.setSelected(true);
    gb.add(r1);
    gb.add(r2);
    gb.add(r3);
   
    fe.add(r1); 
   fe.add(r2); 
   fe.add(r3);
     fe.add(entree);
    fe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
fe.show( );
    entree.addActionListener(l);
    fe.setResizable(false);

  }
    public class MonListenerEchange implements ActionListener {
	public void actionPerformed(ActionEvent e) { 
            String response;
  if(r1.isSelected())
  {fe.dispose(); 
  do
        {
            response = JOptionPane.showInputDialog(null, "Quelle lettre voulez-vous échanger?",
         "Entrer une lettre",  JOptionPane.QUESTION_MESSAGE);
            
        }
        while(response.length()!=1);
                chev.echanger(response.charAt(0));
            
  }
    if(r2.isSelected())     
    {fe.dispose(); 
       
        chev.echange(plat);
       
            
    }    
    if(r3.isSelected())
    {fe.dispose(); 
        chev.echange1(plat);
    }
	
}  
}
}
